package cn.iocoder.yudao.module.currency.dal.mysql.rate;

import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.currency.dal.dataobject.rate.ExchangeRateDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.currency.controller.admin.rate.vo.*;

/**
 * 货币汇率 Mapper
 *
 * @author 超管
 */
@Mapper
public interface ExchangeRateMapper extends BaseMapperX<ExchangeRateDO> {

    default PageResult<ExchangeRateDO> selectPage(ExchangeRatePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<ExchangeRateDO>()
                .likeIfPresent(ExchangeRateDO::getCurrencyName, reqVO.getCurrencyName())
                .eqIfPresent(ExchangeRateDO::getBaseCurrency, reqVO.getBaseCurrency())
                .eqIfPresent(ExchangeRateDO::getCurrencyCode, reqVO.getCurrencyCode())
                .eqIfPresent(ExchangeRateDO::getCurrencySymbol, reqVO.getCurrencySymbol())
                .eqIfPresent(ExchangeRateDO::getExchangeRate, reqVO.getExchangeRate())
                .eqIfPresent(ExchangeRateDO::getAreaCode, reqVO.getAreaCode())
                .likeIfPresent(ExchangeRateDO::getAreaName, reqVO.getAreaName())
                .eqIfPresent(ExchangeRateDO::getCurrencySort, reqVO.getCurrencySort())
                .eqIfPresent(ExchangeRateDO::getStatus, reqVO.getStatus())
                .eqIfPresent(ExchangeRateDO::getRemark, reqVO.getRemark())
                .betweenIfPresent(ExchangeRateDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(ExchangeRateDO::getId));
    }

    default ExchangeRateDO selectByCurrencyCode(String currencyCode, String baseCurrency) {
        return selectOne(new LambdaQueryWrapperX<ExchangeRateDO>()
            .eq(ExchangeRateDO::getBaseCurrency, baseCurrency)
            .eq(ExchangeRateDO::getCurrencyCode, currencyCode));
    }

    default List<ExchangeRateDO> selectAvailableList(String currencyName, String currencyCode, String areaName, String baseCurrency) {
        return selectList(new LambdaQueryWrapperX<ExchangeRateDO>()
            .eq(ExchangeRateDO::getBaseCurrency, baseCurrency)
            .likeIfPresent(ExchangeRateDO::getCurrencyName, currencyName)
            .eqIfPresent(ExchangeRateDO::getCurrencyCode, currencyCode)
            .likeIfPresent(ExchangeRateDO::getAreaName, areaName)
            .eq(ExchangeRateDO::getStatus, CommonStatusEnum.ENABLE.getStatus())
            .eq(ExchangeRateDO::getDeleted, false)
            .orderByAsc(ExchangeRateDO::getCurrencySort));
    }

    default List<ExchangeRateDO> selectListByCode(Collection<String> currencyCodes, String baseCurrency) {
        return selectList(new LambdaQueryWrapperX<ExchangeRateDO>()
            .eq(ExchangeRateDO::getBaseCurrency, baseCurrency)
            .in(ExchangeRateDO::getCurrencyCode, currencyCodes)
            .eq(ExchangeRateDO::getStatus, CommonStatusEnum.ENABLE.getStatus())
            .eq(ExchangeRateDO::getDeleted, false));
    }
}
